package com.guanyong.webapi.controllers.api;

import com.guanyong.model.FilmInfoModel;
import com.guanyong.model.FilmModel;
import com.guanyong.model.VideoScoreModel;
import com.guanyong.model.VideoSourceModel;
import com.guanyong.services.FilmServices;
import com.guanyong.services.ObjectClassTypeService;
import com.guanyong.services.VideoScoreService;
import com.guanyong.services.VideoSourceService;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mxk on 2017/6/15.
 */


@RestController
@RequestMapping("/api/film/")
public class FilmApi {
    @Autowired
    FilmServices filmServices;


    @Autowired
    VideoScoreService videoScoreService;

    @Autowired
    VideoSourceService videoSourceService;


    // 获取电影列表接口 根据 名称类型  过滤  注意 过滤掉 不显示的电影-- 完成修改
    @RequestMapping(value = "getfilmlist", method = RequestMethod.GET)
    public ResultObject<HashMap<String,Object>> GetFilmList(@RequestParam String name,
                                                            @RequestParam String filmtype,
                                                            @RequestParam int pno,
                                                            @RequestParam int pagesize,
                                                            @RequestParam int allcount){
        ResultObject<HashMap<String,Object>> resultObject=new ResultObject<HashMap<String,
                Object>>();
        FilmModel filmModel=new FilmModel();
        filmModel.setfName(name);
        filmModel.setfFilmtype(filmtype);
        filmModel.setfShow(0);
        HashMap<String ,Object> hashMap=filmServices.GetFilmList(filmModel,pno,pagesize,allcount);
        resultObject.setResult(hashMap);
        return  resultObject;

    }

    @RequestMapping(value = "getfilmlist1_0", method = RequestMethod.GET)
    public ResultObject<HashMap<String,Object>> GetFilmList1_0(@RequestParam String name,
                                                            @RequestParam String videotype,
                                                            @RequestParam int pno,
                                                            @RequestParam int pagesize,
                                                            @RequestParam int allcount){
        ResultObject<HashMap<String,Object>> resultObject=new ResultObject<HashMap<String,
                Object>>();
        FilmModel filmModel=new FilmModel();
        filmModel.setfName(name);
        filmModel.setfVideotype(videotype);
        filmModel.setfShow(0);
        HashMap<String ,Object> hashMap=filmServices.GetFilmList1_0(filmModel,pno,pagesize,allcount);
        resultObject.setResult(hashMap);
        return  resultObject;

    }

    @RequestMapping(value = "getfilmallcount", method = RequestMethod.GET)
    public ResultObject<Integer> getfilmallcount(){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();

        Integer allcount =filmServices.GetFilmAllCount();
        resultObject.setResult(allcount);
        return  resultObject;

    }



    // 获取电影列表接口 根据 名称类型  过滤  注意 过滤掉 不显示的电影-- 完成修改
    @RequestMapping(value = "getfilmsubjectlist", method = RequestMethod.GET)
    public ResultObject<HashMap<String,Object>> GetFilmSubjectList(@RequestParam Integer Subjectid,
                                                            @RequestParam int pno,
                                                            @RequestParam int pagesize,
                                                            @RequestParam int allcount){
        ResultObject<HashMap<String,Object>> resultObject=new ResultObject<HashMap<String,
                Object>>();

        HashMap<String ,Object> hashMap=filmServices.GetFilmBySubjectList
                (Subjectid,pno,pagesize,allcount);
        resultObject.setResult(hashMap);
        return  resultObject;

    }



    //修改成已显示的了。
    @RequestMapping(value = "getByPlayctfilmlist", method = RequestMethod.GET)
    public ResultObject<HashMap<String,Object>> GetByPlayctfilmlist(@RequestParam int limit){
        ResultObject<HashMap<String,Object>> resultObject=new ResultObject<HashMap<String,
                Object>>();
        HashMap<String ,Object> hashMap = new HashMap<String ,Object>();
        if (limit>0 && limit<10){
            hashMap=filmServices.GetByfPlayctFilmList(limit);
        }else{
            resultObject.setCode(ResultCode.ParamsError);
        }
        resultObject.setResult(hashMap);
        return  resultObject;

    }

    //修改成已显示的了。
    @RequestMapping(value = "getfilmtypslist", method = RequestMethod.GET)
    public ResultObject<HashMap<String,List<FilmModel>>> GetFilmTypesList(

            @RequestParam String filmtypestr,
            @RequestParam int count){
        ResultObject<HashMap<String,List<FilmModel>>> resultObject=new ResultObject<HashMap<String,
                List<FilmModel>>>();
        HashMap<String ,List<FilmModel>> hashMap=filmServices.GetFilmTypeIdList(filmtypestr,count);
        resultObject.setResult(hashMap);
        return  resultObject;

    }
    //修改成已显示的了。
    @RequestMapping(value = "gethotnewsfilmlist", method = RequestMethod.GET)
    public ResultObject<List<FilmModel>> GetHotNewsFilmList(
            @RequestParam int hotcount,
            @RequestParam int newscount){
        ResultObject<List<FilmModel>> resultObject=new ResultObject<List<FilmModel>>();
        List<FilmModel> list=filmServices.GetNewsHotFilmList(newscount,hotcount);
        resultObject.setResult(list);
        return  resultObject;

    }

    //修改成已显示的了。
    @RequestMapping(value = "getnewsvideolist", method = RequestMethod.GET)
    public ResultObject<HashMap<String,Object>> getnewsvideolist(
            @RequestParam int filmcount,
            @RequestParam int shortvideoct){
        ResultObject<HashMap<String,Object>> resultObject=new ResultObject<HashMap<String,Object>>();

        HashMap<String,Object> hashMap=new HashMap<String, Object>();
        List<FilmModel> list=filmServices.GetNewsHotFilmList(filmcount,0);
        hashMap.put("filmlist",list);
        List<FilmModel> videolist=new ArrayList<FilmModel>();
        hashMap.put("videolist",videolist);
        resultObject.setResult(hashMap);
        return  resultObject;

    }


    // 获取短视频
    @RequestMapping(value = "gettopshortvideo", method = RequestMethod.GET)
    public ResultObject<List<FilmModel>> gettopshortvideo(
            @RequestParam int count){
        ResultObject<List<FilmModel>> resultObject=new ResultObject<List<FilmModel>>();
        List<FilmModel> videolist=new ArrayList<FilmModel>();
        resultObject.setResult(videolist);
        return  resultObject;
    }

    //随机显示
    //修改成已显示的了。
    @RequestMapping(value = "guessfilmlist", method = RequestMethod.GET)
    public ResultObject<List<FilmModel>> GetGuessFilmList(
            @RequestParam String filmtype,
            @RequestParam int count){
        ResultObject<List<FilmModel>> resultObject=new ResultObject<List<FilmModel>>();
        FilmModel filmModel=new FilmModel();
        filmModel.setfFilmtype(filmtype);
        List<FilmModel> randList=filmServices.GetRandomFilmList(filmModel,count);
        resultObject.setResult(randList);
        return  resultObject;

    }


    @RequestMapping(value = "getfilminfo", method = RequestMethod.GET)
    public ResultObject<HashMap<String,Object>> GetFilmList(@RequestParam String filmid){
        ResultObject<HashMap<String,Object>> resultObject=new ResultObject<HashMap<String,
                Object>>();
        HashMap<String ,Object> hashMap=new HashMap<String, Object>();
        FilmModel filmModel=filmServices.GetFilmModelById(filmid);
        hashMap.put("film",filmModel);
        VideoScoreModel videoScoreModel=videoScoreService.GetVideoScoreByObjectId(1,filmid);

        hashMap.put("videoscore",videoScoreModel);

        FilmInfoModel filmInfoModel=filmServices.GetFilmInfoModelById(filmid);

        hashMap.put("filminfo",filmInfoModel);
        List<VideoSourceModel> sourceModelList=videoSourceService.GetVideoScorceByObjectId(1,
                filmid,1);
        hashMap.put("videosourcelist",sourceModelList);
        resultObject.setResult(hashMap);
        return  resultObject;

    }





}
